﻿// This code is released under the BSD license.
namespace PugLib
{
    using System;
    using System.Globalization;

    public class LogEntry
    {
        private readonly Guid _id;
        private readonly bool _showInLocalTime;

        public LogEntry(string message, bool showInLocalTime)
        {
            _id = Guid.NewGuid();
            Message = message;
            Stamp = DateTime.UtcNow;
            _showInLocalTime = showInLocalTime;
        }

        public Guid Id
        {
            get { return _id; }
        }

        public string Message { get; set; }

        /// <summary>
        /// Time in UTC of when this entry was constructed.
        /// </summary>
        public DateTime Stamp { get; private set; }

        public override string ToString()
        {
            DateTime timeToShow = Stamp;
            if (_showInLocalTime)
            {
                timeToShow = Stamp.ToLocalTime();
            }
            return string.Format(CultureInfo.CurrentUICulture, "{0}\t{1}{2}",
								 timeToShow.ToString("u", CultureInfo.CurrentCulture), Message, Environment.NewLine);
        }
    }
}